import pygame
import math
import random

class BadGuy (pygame.sprite.Sprite):
    
    def __init__(self,image,x,y):
        pygame.sprite.Sprite.__init__(self)
        self.image = image
        self.rect = self.image.get_clip()
        self.x = x
        self.y = y
       

    def update(self,args):
        width,height = args[0],args[1]
        arrows = args[2]
        health = args[3]
        window = pygame.display.get_surface()
        self.x -= 1

        self.rect.top = self.x 
        self.rect.left = self.y 

        if self.x < 0 or self.x > width or self.y < 0 or self.y > height:
            health -= random.randint(2,20)
            self.kill()
            return health

        for arrow in arrows:
            if pygame.sprite.collide_rect(arrow,self) == True:
                self.kill()
                arrow.kill()

        if self.alive():
            window.blit(self.image, (self.x, self.y))
            
    
